<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_quntui/model')->方法名();
*/
namespace jy_quntui;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	public function checkvip(){
		$user=pdo_get('jy_quntui_user',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));		
		$pluginset=$this->plugin_setting('basic');
		if($pluginset['no_vip']!=1){
			if(!$user['isvip']){
					exi('只有VIP会员才能操作！','error','/home/');
			}elseif($user['viptime']<time()){
					exi('您的VIP已过期，无权操作！','error','/home/');
			}
		}
		return true;
	}
	//0表示系统的
	public function check_isaddqun($qun_id=0){
		$addlog=pdo_get('jy_quntui_quan_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'qun_id'=>$qun_id));		
		if(!$addlog['isadd']){
			$pluginset=$this->plugin_setting('basic');
			if(!$pluginset['chat_id'] && !$pluginset['no_jiaewm']){
				exi('系统没有设置当前企业微信群ID（联系管理员-基本设置-企业微信设置）','error');
			}
			/*$quninfo=model('core/wxwork_userapi')->get_qunitem($pluginset['chat_id']);
			$member_list=json_decode($quninfo['member_list']);
			foreach($member_list as $item){
				if($item['userid']){
					
				}
			}*/
			return false;
		}
		return true;
	}
	public function checklogin(){
		if(!$_SESSION['uid']){
			return false;
		}
		$user_id=pdo_getcolumn('jy_quntui_user',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');
		$member=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id','credit1','credit2','pcd','sex','mobile','groupid','avatar','nickname'));
		if(!$user_id){
			$insert=array(
				'mid'=>$_SESSION['uid'],
				'uniacid'=>$_SESSION['uniacid'],
				'nickname'=>$member['nickname'],
				'avatar'=>$member['avatar'],
				'sex'=>$member['sex'],
				'city'=>$member['pcd'],
				'updatetime'=>TIMESTAMP,
				'createtime'=>TIMESTAMP,
			);
			pdo_insert('jy_quntui_user',$insert);
		}
		return true;
	}
	public function checkpaohui($action=''){
		$pluginset=$this->plugin_setting('basic');
		$systemsite=core_setting('site');
		$url=custom_url($action);
		if(($pluginset['ispaohui']==1 || $systemsite['open_paohui']==1) && $_SESSION['openid']){
			$num=count($pluginset['paohui_yuming']);
			if(!$num){
			  exi('请联系管理员设置炮灰域名！基本设置--炮灰机制','error');	
			}
			$num--;
			$index=rand(0,$num);
			$paohui_yuming=$pluginset['paohui_yuming'][$index]['yuming'];
			if($paohui_yuming != SITEROOT){
				$nowlink=$paohui_yuming.'/custom/'.$url;
				exi('','',$nowlink);
			}
		}
	}
}
?>